import { addTypeDao, delTypeDao, findAllTypeDao, findTypeByPageDao, getAllCountDao, updateTypeDao } from "../Dao/typeDao.js"

export const addTypeServ = async (name, color) => {
    await addTypeDao(name, color);
    return{
        code:0,
        msg:"add OK"
    }
}

export const deleteTypeServ = async (id) => {
    await delTypeDao(id)
    return {
        code:0,
        msg:"Delete OK"
    }
}

export const updateTypeServ = async (id,obj) => {
    await updateTypeDao(id,obj)
    return {
        code: 0,
        msg: "update OK"
    }
}

export const findAllTypeServ = async() => {
    const data = await findAllTypeDao()
    return {
        data,
        msg:"all type",
        code: 0
    }
}

export const findTypeByPageServ = async(page,size)=>{
    const data = await findTypeByPageDao(page,size)
    const total = await getAllCountDao();
    return {
        msg: 'findPage',
        code: 0,
        data: {
            total,
            data
        }
    }
}